#define _CRT_SECURE_NO_WARNINGS 1
#include"AVL.h"
#include<queue>

//#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>>g(n + 1);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<bool>vis(n + 1);
    priority_queue<int, vector<int>,greater<int>>q;
    vis[1] = true;
    q.push(1);
    while (q.size()) {
        int v = q.top();
        q.pop();
        cout << v << " ";
        for (int i : g[v]) {
            if (!vis[i]) {
                q.push(i);
                vis[i] = true;
            }
        }
    }
    return 0;
}
//void test()
//{
//	AVLTree<int, int>tree;
//	srand(time(0));
//	int n = 1000;
//	for (int i = 0; i < n; i++)
//		tree.insert(make_pair(i, rand()));
//	cout << tree.Isbalance() << endl;
//}
//int main()
//{
//	test();
//
//	return 0;
//}